package org.azj.dbOperatorComponent;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class UpdateCommand extends DbNonQueryCommand
{
	String whereFilter;
	String updateContents;
	String tableName;
	
	public UpdateCommand(
			String tableName, 
			String whereFilter, 
			String updateContents)
	{
		this.tableName = tableName;
		this.whereFilter = whereFilter;
		
		this.updateContents = updateContents;
	}

	@Override
	public PreparedStatement getStatement(Connection conn) throws Exception
	{
		PreparedStatement preparedStatement = conn.prepareStatement(
				String.format("UPDATE %s SET %s WHERE %s", 
						tableName, updateContents, whereFilter));
		return preparedStatement;
	}
	
	@Override
	void doExecute(PreparedStatement preparedStatement) throws SQLException{
		preparedStatement.executeUpdate();
	}
}